<?php
declare (strict_types=1);

namespace addons\V2\admin\controller;

use think\facade\View;

class ProductCate extends \app\admin\controller\Base
{

    protected string $pk = 'id';

    protected string $model = '\addons\V2\admin\model\ProductCate';

    public function index()
    {
        $sys_id = $this->request->get('sys', 1);
        View::assign('sys_id', $sys_id);
        View::assign('list', $this->model::getAll($sys_id));
        return View::fetch($this->app->getRootPath() . 'addons/V2/admin/view/product_cate/index.html');
    }

    public function add($tpl = 'form/add')
    {
        $sys_id = $this->request->get('sys', 1);
        View::assign('sys_id', $sys_id);
        return parent::add($this->app->getRootPath() . 'addons/V2/admin/view/product_cate/edit.html'); // TODO: Change the autogenerated stub
    }

    public function edit($id = '', $pid = '', $tpl = '')
    {
        $p_title = '';
        if ($pid) {
            $p_title = $this->model::where('id', $pid)->value('title');
        }
        View::assign('p_title', $p_title);
        View::assign('form', ['title' => '图标', 'field' => 'icon', 'value' => 1]);
        return parent::edit($id, $this->app->getRootPath() . 'addons/V2/admin/view/product_cate/edit.html');
    }


    public function getCate()
    {
        $id = $this->request->param('id', 0);
        $sys = $this->request->param('sys', 1);
        return json($this->model::getCate($id,$sys));
    }
}
